<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <script src="./js/earthsdk.js"></script>
    <!-- 面板的样式放到css文件内 -->
    <link rel="stylesheet" href="./css/example1.css" />
    <title>Cesium地球初始化</title>
    <style>
      html,
      body,
      #app {
        width: 100%;
        height: 100%;
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>

  <body>
    <div id="app"></div>
    <div id="panel">
      <input
        type="range"
        min="0"
        max="1"
        step="0.1"
        value="0.1"
        id="rangeInput"
      />
      <div class="panel-text">
        <p>0</p>
        <p>1</p>
      </div>
    </div>
    <script>
      /** ---------------------------------地球创建------------------------------------**/

      // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

      const { ESObjectsManager } = XE2["esobjs-xe2-plugin-main"];
      const objm = new ESObjectsManager();
      window.g_objm = objm;

      // 创建Cesium视口
      const viewer = objm.createCesiumViewer({
        domid: document.getElementById("app"),
      });
      //监听视口变化  允许Manager控制SunSky
      objm.activeViewerChanged.don((viewer) => {
        if (!viewer) return;

        if (objm.activeViewer.typeName === 'ESUeViewer') {
            objm.activeViewer.sunSkyControlled = true
            objm.activeViewer.fog = 0.1

        }
      });

      viewer.statusChanged.don((status) => {
        if (status == "Created") {
          // 视口创建完成，飞到初始视角位置
          objm.activeViewer.flyIn(
            [116.4039999933472, 39.90552136838816, 14],
            [
              0.000003953799176735324, -11.414076659004925,
              0.005499830662451785,
            ],
            3
          );
        }
      });

      // 通过json创建一个影像图层
      const imageryLayer = objm.createSceneObjectFromJson({
        id: "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
        type: "ESImageryLayer",
        url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
      });

      /**-------------------------------------天气-雾-------------------------------**/
      /** activeViewer表示当前视口
             cesium视口下的雾效果通过0和1控制开关，0表示关闭，1表示开启
             ue视口下的雾效果通过0到1调节雾量
            
        */
      objm.activeViewer.fog = 0.1;

      // 添加视角对象实现飞入效果
      const { ESCameraView } = XE2["esobjs-xe2-plugin-main"];
      const sceneObject = objm.createSceneObject(ESCameraView);
      sceneObject.position = [116.404, 39.904, 18];
      sceneObject.rotation = [
        58.1806113788587, 7.827484164228053, 359.9866160377612,
      ];

      // 添加事件监听器，当拖动条的值发生变化时触发
      const ipt = document.getElementById("rangeInput");
      ipt.addEventListener("input", function () {
        console.log(ipt.value, "ipt");
        objm.activeViewer.fog = Number(ipt.value);
      });
    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
      <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
  </body>
</html>
